﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using Sunboxsoft.Common;

namespace Sunboxsoft.ASMS.Client.Domain.Service
{
    /// <summary>
    /// 结算收银任务
    /// </summary>
    public class CheckOutService
    {

        public ServiceResult CheckOutPackagePurchaseBill(Guid billId, WebRef.CheckOutData checkOutData, WebRef.EPayRecord[] payRecordArray)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.CheckOutPackagePurchaseBill(billId, checkOutData, payRecordArray);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 收银-结算单
        /// </summary>
        /// <param name="billId"></param>
        /// <param name="payRecordArray"></param>
        /// <returns></returns>
        public ServiceResult CheckOutSettlementBill(Guid billId, WebRef.CheckOutData checkOutData, WebRef.EPayRecord[] payRecordArray)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.CheckOutSettlementBill(billId, checkOutData, payRecordArray);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }

        /// <summary>
        /// 
        /// 收银-充值单
        /// </summary>
        /// <param name="billId"></param>
        /// <param name="invoiceInfo"></param>
        /// <param name="payRecordArray"></param>
        /// <returns></returns>
        public ServiceResult CheckOutRechargeBill(Guid billId, WebRef.CheckOutData checkOutData, WebRef.EPayRecord[] payRecordArray)
        {
            WebRef.ASMSWebService service = RemoteInfo.GetASMSService();
            try
            {
                WebRef.ServiceResult result = service.CheckOutRechargeBill(billId, checkOutData, payRecordArray);
                if (result.IsSuccess)
                {
                    return new ServiceResult();
                }
                return new ServiceResult(result.ErrorCode, result.Message);
            }
            catch (Exception ex)
            {
                return new ServiceResult(1, ex.Message);
            }
            finally
            {
                RemoteInfo.ReleaseASMSService(service);
            }
        }
    }
}
